function [lpostd,likel,lpriord,lpriord_ss,flag_ok]=...
lmjPosteriorGeneral(parest,parvec,parStru,posStru,model,dataStru,prpar,prss,filterStru,flags)
% ======================================================================
% [lpostd,likel,lpriord,lpriord_ss,flag_ok]=...
% lmjPosteriorGeneral(parest,parvec,posStru,model,dataStru,prpar,prss,filterStru,flags)
%
%% LikelNSplitsGeneral.m
%
% This code estimates the likelihood of a DSGE model with potentially 
% 1) NaNs in the observables  model 
% 2) NB Breaks, where the solution matrices have NB pages 
% 
% No temporal aggregation 
% 
%% Inputs 
% parest:       portion of parameter vector being estimated
%
% parStru:      structure with
%               .param if the model is solved using a vector of parameters
%           OR  .namesEstimated if the model is solved using
%
% posStru:      .param.estimated    rows of paramter vector estimated
%               .steady.estimated   rows of ss vector being estimated 
%                                   leave empty if none 
%
% model:        .handle
%               .addsol
%               .solveOpt
%
% dataStru:     .data     [T n] vector of data
%               .trainVec [2 1] position to start and end the sample in
%                         computing the likelihood
%
% filterStru:   .tauVec   vector of indicators of which pages to use for
%                         each observation
%               .aZero    Initial state,  if flags.initialCond==1
%               .pZero    Initial VCV,    if flags.initialCond==1
%
% flags        .initialCond
% =======================================================================
lpostd=-1e15;
likel=-inf;
lpriord=-inf;
lpriord_ss=-inf; 
flag_ok=0;
%% Keep this always to ensure working with latest Value
parvec(posStru.param.est)=parest;
% 
% function [likel,ssvec,flag_ok,lht]=...
% likelNSplitsGeneral(parest,parStru,posStru,model,dataStru,filterStru,flags)
[likel,ssvec,flagLikelOK]=feval(filterStru.funcLikel,parest,parStru,...
    posStru,model,dataStru,filterStru,flags);

%% Likelihood
if flagLikelOK~=1; return; end
%% Prior Density of Parameters
%% Modify this when ready to move to a structure base 
lpriord=sum(feval(@priordens,parvec,prpar.prior,prpar.alphap,prpar.betap,prpar.lbnd,prpar.ubnd));
if isinf(abs(lpriord))==1;return;end;
if isnan(lpriord)==1; return;end;
%% Prior Density on Steady State
if ~isempty(posStru.steady.est)
    lpriord_ss = sum(feval(@priordens,ssvec(posStru.steady.est), prss.prior, prss.alphap, prss.betap, prss.lbnd, prss.ubnd));
    if isinf(abs(lpriord_ss))==1;return;end
else
    lpriord_ss=0;
end
%% log likelihood
lpostd = lpriord + lpriord_ss + likel;
flag_ok=1;